package com.ruoyi.lvlian.domain;

import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.lvlian.util.FormulaToDoubleConverter;
import com.ruoyi.lvlian.util.PercentageStringToIntConverter;
import com.ruoyi.lvlian.util.UniversalConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;


/**
 * 发票信息对象 lv_invoice_info  以发票去串联全部
 *
 * @author liyuxi
 * @date 2024-05-09
 */
@Data
@ToString
@ApiModel(value = "发票信息对象", description = "发票信息对象")
public class InvoiceInfo {
    private static final long serialVersionUID = 1L;
    private String id;

    @ExcelProperty("发票抬头")
    @ApiModelProperty(value = "发票表头")
    private String invoiceTitle;

    @ExcelProperty("发票代码")
    @ApiModelProperty(value = "发票代码")
    private String invoiceCode;

    @ExcelProperty("发票号码")
    @ApiModelProperty(value = "发票号码")
    private String invoiceNum;

    @ExcelProperty("数电票号码")
    @ApiModelProperty(value = "数电票号码")
    private String digitalInvoiceNum;

    @ExcelProperty("发票类型")
    @ApiModelProperty(value = "发票类别(专票和普票)")
    private String invoiceType;

    @ExcelProperty("开票人")
    @ApiModelProperty(value = "开票人")
    private String invoicerName;

    @ExcelProperty("购买方识别号")
    @ApiModelProperty(value = "购买方信用代码统一社会信用代码/纳税人识别号")
    private String buyerLicense;

    @ExcelProperty("购买方名称")
    @ApiModelProperty(value = "购买方名称")
    private String buyerName;

    @ExcelProperty("销售方识别号")
    @ApiModelProperty(value = "销售方信用代码统一社会信用代码/纳税人识别号")
    private String sellerLicense;

    @ExcelProperty("销售方名称")
    @ApiModelProperty(value = "销售方名称")
    private String sellerName;

    @ExcelProperty("开票日期")
    @ApiModelProperty(value = "开票日期 yyyy-MM-dd")
    private String invoiceDate;

    @ExcelProperty("金额")
    @ApiModelProperty(value = "不含税金额(金额合计)")
    private Double excludeTaxAmount;

    @ExcelProperty(value = "税额" )
    private Double taxAmount;

    @ExcelProperty(value = "税率", converter = PercentageStringToIntConverter.class)
    @ApiModelProperty(value = "税率/征收率")
    private int taxRate;

    @ExcelProperty(value = "价税合计"  )
    @ApiModelProperty(value = "价税合计含税金额(两个相加)")
    private Double totalAmount;


    @ApiModelProperty(value = "关联状态  是=否关联到支付回单")
    private String associationSts;

    @ApiModelProperty(value = "结算状态")
    private String settlementStatus;

    @ApiModelProperty(value = "物流状态")
    private String logisticsStatus;

    @ExcelProperty("发票票种")
    @ApiModelProperty(value = "税收类型增值税")
    private String taxType;

    @ApiModelProperty(value = "发票图片有可能是多个，附件id，多个逗号隔开")
    private String invoiceImg;

    @ApiModelProperty(value = "登记时间 yyyy-MM-dd")
    private String createDate;

    @ExcelProperty("所属公司编码")
    @ApiModelProperty(value = "")
    private String orgCode;

    @ApiModelProperty(value = "录入人")
    private String createUser;

//    @ExcelProperty("对应支付单编号")
//    @ApiModelProperty(value = "回单交易流水号-一个发票对应一个支付")
//    private String paymentNum;

    @ExcelProperty("备注")
    @ApiModelProperty(value = "备注")
    private String remark;


    @ExcelProperty("废品收购")
    @ApiModelProperty(value = "废品收购")
    private String scrapPurchase;


    public String getInvoiceDate() {
        if (StringUtils.isNotEmpty(invoiceDate) && DateUtils.isValidDateTime(invoiceDate)) {
            invoiceDate = invoiceDate.substring(0, 10);
        }
        return invoiceDate;
    }

    public void setInvoiceDate(String invoiceDate) {
        this.invoiceDate = invoiceDate;
    }

    public String getInvoiceImg() {
        if("https://data.lvlianhengsheng.com/dev-api".equalsIgnoreCase( invoiceImg)  || StringUtils.countMatches(  invoiceImg ,"http" )>1    ){
            return null;
        }
        if (com.ruoyi.common.core.utils.StringUtils.isNotEmpty( invoiceImg ) &&  !invoiceImg.contains( "http")) {
            return "https://data.lvlianhengsheng.com/dev-api/file/fileAttachmentInfo/viewPdf?key=" + invoiceImg;
        }
        return invoiceImg;
    }





    public Double getTaxAmount() {
        return taxAmount;
    }

    public void setTaxAmount(Double taxAmount) {
        this.taxAmount = taxAmount;
    }

    public Double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public String getInvoiceTitle  () {

        if (com.ruoyi.common.core.utils.StringUtils.isEmpty(invoiceTitle)) {
            return getBuyerName();
        }
        return invoiceTitle;
    }
}






